import {request} from "../../request/index.js"


const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    tabs: [
      {
        id: 0,
        name: '正常停电',
        isActive: true
      },
      {
        id: 1,
        name: '故障停电',
        isActive: false
      }
    ],
    historyList: [],
    badHistoryList: [],
    stationAndBusbar: '',
    superior35kv: '',
    belong10kv: ''
  },
  onLoad: function (options) {
    var historyList = JSON.parse(options.historyList)
    this.setData({
      historyList,
      stationAndBusbar: options.stationAndBusbar,
      superior35kv: options.superior35kv,
      belong10kv: options.belong10kv
    })
    request({
      url: '/client/query/malfunction/' + app.userId,
      method: 'POST',
      data: {
        stationAndBusbar: this.data.stationAndBusbar,
        superior35kv: this.data.superior35kv,
        belong10kv: this.data.belong10kv
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    })
    .then(res => {
      console.log(res)
      var badHistoryList = []
      badHistoryList = res.data
      this.setData({
        badHistoryList
      })
    })
  },
  handleItemTags(e) {
    const {index} = e.detail
    let {tabs} = this.data
    tabs.forEach((v, i) => i===index? v.isActive=true: v.isActive=false)
    this.setData({
      tabs
    })
  }
})